package com.javalong.mir.controller;

import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.javalong.mir.common.util.QiNiuUtils;
import com.javalong.mir.dwz.vo.ErrorCode;
import com.javalong.mir.dwz.vo.ResponseVO;

@Controller
@RequestMapping("image")
public class ImageController {
	
	public final static String QINIU_PREFIX = "http://p122jqsjp.bkt.clouddn.com/";
	@RequestMapping("upload")
	@ResponseBody
	public ResponseVO upload(@RequestParam(value="Filedata") MultipartFile uploadImage){
		try {
			String key = QiNiuUtils.upload(uploadImage.getBytes());
			return new ResponseVO(QINIU_PREFIX+key);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ResponseVO(null, ErrorCode.SERVER_ERROR, "上传失败");
	}
}
